package com.ykt.interceptor;

import com.jfinal.aop.Duang;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.ykt.cache.UserCache;
import com.ykt.vo.ResultStatus;
import com.ykt.vo.ResultVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author long.hua
 * @version 1.0.0
 * @since 2016-01-17 13:28
 */
public class AuthInterception implements Interceptor {
    private final static Logger LOGGER = LoggerFactory.getLogger(AuthInterception.class);

    private UserCache userCache = Duang.duang(UserCache.class);


    @Override
    public void intercept(Invocation inv) {
        Controller controller = inv.getController();
        int userId = controller.getParaToInt("userId", -1);
        if (userId == -1) {
            controller.renderJson(new ResultVo(ResultStatus.NOT_LOGIN, ResultStatus.NOT_LOGIN_MSG));
        } else {
            inv.invoke();
        }
    }

}
